/*
 * Middleware
 * Copyright (C) 2010/11
 * Riccardo Pulvirenti, Giuseppe Ravidà, Andrea Tino
 *
 * This program is free software: you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation, either version 3 of the License, or
 * (at your option) any later version.
 *
 * This program is distributed in the hope that it will be useful,
 * but WITHOUT ANY WARRANTY; without even the implied warranty of
 * MERCHANDABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
 * GNU General Public License for more details.
 *
 * You should have received a copy of the GNU General Public License
 * along with this program. If not, see http://www.gnu.org/licenses
 */

/*!
 * File: data.hpp
 */

#ifndef _DATA_HPP_
#define _DATA_HPP_

#include <iostream>
#include <string>
#include <boost/archive/text_oarchive.hpp>
#include <boost/archive/text_iarchive.hpp>

#include "task_descriptor.hpp"

//-----------------------------------------------------------------------------
// Class definitions
namespace middleware {
/*! \class Data
 * \brief Stores data of an executable task.
 *
 * Represents data of an executable TaskDescriptor. When a TaskDescriptor is
 * executable, to execute it, a Worker, needs to access its Data in order
 * to collect binaries and run them.
 */
class Data {
public:
	/*!
	 * Constructs a dummy Data object with a static string and a zero integer.
	 * Owner TaskDescriptor is set to zero.
	 */
	Data() {
		this->_data_str = std::string("data");
		this->_data_int = 0;
		this->_owner_task_id = 0;
	}
	/*!
	 * Constructs a Data object by specifying string data and integer data.
	 * Owner TaskDescriptor is set to zero.
	 * \param str String data to associate to this object.
	 * \param i Integer data to associate to this object.
	 */
	Data(const std::string& str, int i) {
		this->_data_str = str;
		this->_data_int = i;
		this->_owner_task_id = 0;
	}
	/*!
	 * Copy constructor.
	 */
	Data(const Data& data) {
		this->_data_str = data._data_str;
		this->_data_int = data._data_int;
		this->_owner_task_id = data._owner_task_id;
	}
	/*!
	 * Destructor.
	 */
	~Data() {

	}
	/*!
	 * Gets the string data stored in the object.
	 * \returns Returns the string data in the object.
	 */
	std::string get_data_str() {
		return this->_data_str;
	}
	/*!
	 * Gets the integer data stored in the object.
	 * \returns Returns the integer data in the object.
	 */
	int get_data_int() {
		return this->_data_int;
	}
	/*!
	 * Gets the ownser TaskDescriptor's TaskId to which this object is
	 * belongs to.
	 * \returns Returns the TaskId of the TaskDescriptor owning this object.
	 */
	TaskId get_owner_task_id() {
		return this->_owner_task_id;
	}
	/*!
	 * Sets the string data stored in the object.
	 * \param str_data The string data in the object.
	 */
	void set_data_str(std::string str_data) {
		this->_data_str = str_data;
	}
	/*!
	 * Sets the integer data stored in the object.
	 * \param int_data The ineger data in the object.
	 */
	void set_data_int(int int_data) {
		this->_data_int = int_data;
	}
	/*!
	 * Sets the ownser TaskDescriptor's TaskId to which this object is
	 * belongs to.
	 * \param tid The TaskId of the TaskDescriptor owning this object.
	 */
	void set_owner_task_id(TaskId tid) {
		this->_owner_task_id = tid;
	}
private:
	friend class boost::serialization::access;
	/*!
	 * BOOST serialization function.
	 */
	template<class Archive>
	void serialize(Archive & ar, const unsigned int version) {
		ar & _data_str;
		ar & _data_int;
		ar & _owner_task_id;
	}
	/*!
	 * Data representation string.
	 */
	std::string _data_str;
	/*!
	 * Data representation int.
	 */
	int _data_int;
	/*!
	 * Id of the owner task.
	 */
	TaskId _owner_task_id;
}; /* Data */
} /* middleware */

#endif
